package cn.gq.sssm.controller;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @author ASUS
 * @date 2020/5/7
 */
@Controller
@RequestMapping("/user")
public class UserController {


    @RequiresPermissions("user:list")
    @RequestMapping("/list")
    public String index(){
        return "userList";
    }


    @RequestMapping("/login")
    public String login(Model model, HttpServletRequest request){

        System.out.println("1111");
        String attributr = (String) request.getAttribute("shiroLoginFailure");

        if (UnknownAccountException.class.getName().equals(attributr)) {
            model.addAttribute("errorMsg","亲,账号不存在!!");
        } else if (IncorrectCredentialsException.class.getName().equals(attributr)){

            model.addAttribute("errorMsg","亲,密码错误!");
        }
        return "forward:/login.jsp";
    }
}
